package service

import (
	"github.com/jinzhu/gorm"

	"github.com/xdhuxc/asset-management-system/src/model"
)

type dictionaryService struct {
	db *gorm.DB
}

func newDictionaryService(db *gorm.DB) *dictionaryService {
	return &dictionaryService{db}
}

func (d *dictionaryService) Get(groupID int) ([]model.Dictionary, error) {
	var ds []model.Dictionary

	if err := d.db.Model(&model.Dictionary{}).
		Select([]string{"label", "value"}).
		Where("group_id = ?", groupID).
		Find(&ds).Error; err != nil {
		return ds, err
	}

	return ds, nil
}
